<?php

namespace services\clinic;

use Yii;
use common\components\Service;
use common\models\clinic\ProjectBind;

/**
 * Class ProjectBindService
 * @package services\clinic
 */
class ProjectBindService extends Service
{
    /**
     * 查找治疗项目映射信息信息
     *
     * @param array $condition
     * @return ProjectBind|null
     */
    public function findInfo(array $condition = []): ?ProjectBind
    {
        $query = ProjectBind::find();

        isset($condition['clinic_project_id']) && $query->andWhere(['clinic_project_id' => $condition['clinic_project_id']]);
        isset($condition['treatment_room_id']) && $query->andWhere(['treatment_room_id' => $condition['treatment_room_id']]);

        return $query->one();
    }

    /**
     * 查找映射列表
     *
     * @param array $condition
     * @return array|\yii\db\ActiveRecord[]
     */
    public function findList(array $condition = [])
    {
        $query = ProjectBind::find();

        isset($condition['clinic_project_id']) && $query->andWhere(['clinic_project_id' => $condition['clinic_project_id']]);
        isset($condition['treatment_room_id']) && $query->andWhere(['treatment_room_id' => $condition['treatment_room_id']]);

        return $query->asArray()->all();
    }

}